package org.jianfa.mq.seckill.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.jianfa.mq.seckill.entity.po.Users;
import org.jianfa.mq.seckill.entity.vo.Result;
import org.jianfa.mq.seckill.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogginController {

    @Autowired
    private UsersMapper usersMapper;

    @PostMapping("/seckill/login")
    public Result<Users> login() {
        Subject subject = SecurityUtils.getSubject();
        Object principal = subject.getPrincipal();
        String username = (String) principal;
        Users users = usersMapper.selectByUsername(username);
        return Result.success(users);
    }

    @GetMapping("/seckill/loginSuccess")
    public Result<Users> loginSuccess() {
        Subject subject = SecurityUtils.getSubject();
        Object principal = subject.getPrincipal();
        String username = (String) principal;
        Users users = usersMapper.selectByUsername(username);
        return Result.success(users);
    }
}
